home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98a.txt / 000016_icon-group-sender _Fri Jan 23 08:51:13 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.8.7/8.8.7) with SMTP id IAA13820
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Fri, 23 Jan 1998 08:51:12 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA02167; Fri, 23 Jan 1998 08:51:12 -0700
  7. To: icon-group@optima.CS.Arizona.EDU
  8. Date: Fri, 23 Jan 1998 10:36:44 +0100
  9. From: Anders Holtsberg <andersh@maths.lth.se>
  10. Message-Id: <34C864AC.3AA0@maths.lth.se>
  11. Organization: Lund University
  12. Sender: icon-group-request@optima.CS.Arizona.EDU
  13. Subject: Interesting feature
  14. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  15. Status: RO
  16. Content-Length: 1193
  17.  
  18. There is too little traffic here! Why? The perl and python
  19. newsgroups are full and this ought to be too! In order to 
  20. improve the statistics we can discuss this little feature
  21. I was bitten by when I wrote a program that built a complicated 
  22. tree.
  23.  
  24. procedure main()
  25.    # let's say that mytable is a node in a large tree
  26.    mytable := table([])
  27.    # and that the following is in a deep loop 
  28.    put(mytable["A"], "B")
  29.    if not write(mytable["A"][1]) then write("FAIL 1")
  30.    if not write(mytable["C"][1]) then write("FAIL 2")
  31. end
  32.  
  33. Now as an exercise try to guess what the program writes.
  34.  
  35. I tried to think of some more intuitive way Icon could have
  36. behaved but I found none really.
  37.  
  38. The first solution I came up with was to insert the line 
  39.  
  40.    \mytable["A"] := []
  41.  
  42. before the the put-instruction. Then I came up with removing 
  43. the explicit list creation again by writing
  44.  
  45.    mytable["A"] |||:= ["B"]
  46.  
  47. instead of the put-instruction. This seems astongishingly 
  48. enough to work as expected for nonexisting "A". Is this a 
  49. standard trick among you Icon gurus?
  50.  
  51. For long lists it may slow down things due to the extra 
  52. copying but my lists are short.
  53.  
  54. Comments? Improvements?
  55.  
  56.  
  57. -- Anders Holtsberg
  58.